<template>
  <div class="container">
    <div>
      <div class="menu-navbar">
        <el-button size="small" type="" @click="cancelSubmit">取消</el-button>
        <el-button size="small" type="primary" @click="createSubmit('appendlist')">确 定</el-button>
        
      </div>
      <div>
        <el-form :model="appendlist" label-position="top" size="small" ref="appendlist" :rules="appendrules" label-width="110px">
          <el-row :gutter="20">
            <el-col :span="10">
              <el-form-item label="系统建设单位" prop="developmentUnit">
                <el-input :disabled="true" v-model="unitName" placeholder="系统建设单位" ></el-input>
                
              </el-form-item>
               
            </el-col>
            <el-col :span="2">
              
               <div class="select-container">
                   <el-button size="mini" type="text" @click="selectDeveUnit" style="margin-top: 40px;">选择</el-button>
                </div>
                
              
            </el-col>
            <el-col :span="12">
              <el-form-item label="系统名称（中文）" prop="chName">
                <el-input v-model="appendlist.chName" placeholder="系统中文名称"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="系统名称（英文）" prop="znName">
                <el-input v-model="appendlist.znName" placeholder="系统英文名称"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="状态" prop="status">    
                <el-select v-model="appendlist.status" clearable placeholder="系统状态" :disabled="false">
                  <el-option
                    v-for="item in typeOptions"
                      :key="item.type"
                      :label="item.value"
                      :value="item.type">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="系统建设时间" prop="constructTime" :show-overflow-tooltip='true'>
                  <el-date-picker type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:ss" placeholder="系统建设时间" v-model="appendlist.constructTime" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="系统运维截止时间" prop="operEndTime" :show-overflow-tooltip='true'>
                  <el-date-picker type="date" format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:ss" placeholder="系统运维截止时间" v-model="appendlist.operEndTime" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="系统承建单位" prop="constructionUnit">
                <el-input v-model="appendlist.constructionUnit" placeholder="系统承建单位"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="系统运维单位" prop="operUnit">
                <el-input v-model="appendlist.operUnit"  placeholder="系统运维单位"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="系统URL地址" prop="url">
                <el-input v-model="appendlist.url" placeholder="系统URL地址"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="系统IP地址" prop="ip">
                <el-input v-model="appendlist.ip"  placeholder="系统IP地址"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="系统负责人" prop="systemLeader">
                <el-input v-model="appendlist.systemLeader" placeholder="系统负责人"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="负责人办公电话" prop="officePhone">
                <el-input v-model="appendlist.officePhone"  placeholder="负责人办公电话"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="负责人移动电话" prop="mobile">
                <el-input v-model="appendlist.mobile" placeholder="负责人移动电话"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="系统所属网络区域" prop="netArea">
                <el-select v-model="appendlist.netArea" clearable placeholder="系统所属网络区域" :disabled="false">
                  <el-option
                    v-for="item in netAreaOptions"
                      :key="item.type"
                      :label="item.value"
                      :value="item.type">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-dialog
      title="选择建设单位"
      :visible.sync="dialogVisible"
      top="5vh"
      width="70%">
      <el-row>
        <el-col :span="24">
          <el-tree ref='tree'
                   :data="treeData"
                   v-loading="loading"
                   style="height: 400px; overflow: scroll"
                   :props="defaultProps"
                   :expand-on-click-node='false'
                   @node-click="handleNodeClick"
                   node-key="id"
                   :highlight-current='true'
                   :default-expand-all='true'></el-tree>
        </el-col>
        
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>
      </div>
    </div>
  </div>
  
</template>
<script>
import {
  
  treeByParentId,
  treeById
 
} from '@/api/bussSystemManage/orgTreeExt'

import {
  
  subSysInsert
} from '@/api/bussSystemManage/subSystemMgr'
  export default {
    data() {
      return {
        dialogVisible: false,
         treeData: [],
         unitName: '',
         loading: false,
          defaultProps: {
          children: 'children',
          label: 'name'
      },
        appendlist: {
          id: '',
          developmentUnit: '',
          chName: '',
          znName: '',
          status: '',
          constructTime: '',
          operEndTime: '',
          constructionUnit: '',
          operUnit: '',
          url: '',
          ip: '',
          systemLeader: '',
          officePhone: '',
          mobile: '',
          netArea: ''

        },
        appendrules: {
          developmentUnit: [
            { message: '系统建设单位不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 255, message: '长度在 1 到 255 个字符', trigger: 'blur' }
          ],
          chName: [
            { message: '系统中文名称不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
          ],
          znName: [
            { message: '系统英文名称不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
          ],
          status: [
            { message: '系统状态不能为空', required: true, trigger: 'blur' }
           
          ],
          constructTime: [
            { message: '系统建设时间不能为空', required: true, trigger: 'blur' }
          ],
          operEndTime: [
            { message: '系统运维截止时间不能为空', required: true, trigger: 'blur' }
          ],
          constructionUnit: [
            { message: '系统承建单位不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
          ],
          operUnit: [
            { message: '系统运维单位不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' }
          ],
          url: [
            { message: '系统URL地址不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 255, message: '长度在 1 到 255 个字符', trigger: 'blur' }
          ],
          ip: [
            { message: '系统IP地址不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
          ],
           systemLeader: [
            { message: '系统负责人不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
          ],
          officePhone: [
            { message: '办公电话不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
          ],
          mobile: [
            { message: '移动电话不能为空', required: true, trigger: 'blur' },
            { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
          ],
          netArea: [
            { message: '所属网络区域不能为空', required: true, trigger: 'blur' }
          ]
        },
        
         typeOptions: [
          {
            type: '0',
            value: '有效'
          },
          {
            type: '1',
            value: '禁用'
          },
          {
            type: '2',
            value: '删除'
          }
        ],
        netAreaOptions: [
          {
            type: '0',
            value: '政务网'
          },
          {
            type: '1',
            value: '政务网1'
          },
          {
            type: '2',
            value: '政务网2'
          }
        ]
      }
    },
    // 画面刚进入method
  created() {
    
    
  },
    methods: {
      
      createSubmit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            subSysInsert(this.appendlist).then(res => {
              this.$router.push({
              name: 'subSys'
            })
            this.$message({
              type: 'success',
              message: '添加成功!'
            })
              
            }).catch((err) => {
              console.log(err)
              this.$message({
              type: 'danger',
              message: '添加失败!'
            })
            })
           
          } else {
            this.$message({
              type: 'danger',
              message: '添加失败!'
            })
            console.log('error submit!!')
            return false
          }
        })
      },
      
      
      cancelSubmit() {
        this.$router.push({
          name: 'subSys'
        })
      },
      selectDeveUnit(){
        this.dialogVisible = true
        treeByParentId({ parentId: "****",status: "0" }).then(response => {
        this.treeData = response.data.data
      })
      },
      handleNodeClick(data) {
      
     
      this.appendlist.developmentUnit = data.id
      this.unitName = data.name
      this.dialogVisible = false
    //  alert(this.appendlist.developmentUnit)
      
    },
    }
  }
</script>
<style scoped>
  .menu-navbar{
    padding:0 0 20px;
    text-align: right;
  }
  .container{
    padding: 20px;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }
</style>
